package com.study.d025paint;

import javafx.application.Application;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.scene.Scene;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.GridPane;
import javafx.scene.paint.Color;
import javafx.scene.paint.CycleMethod;
import javafx.scene.paint.LinearGradient;
import javafx.scene.paint.Paint;
import javafx.scene.paint.Stop;
import javafx.scene.shape.Rectangle;
import javafx.stage.Stage;

/**渐变线填充
*@description
*@author xtayhame
*date 2020年3月20日
*version
*since v1.0
*/
public class LinearGradientMain extends Application{
	public static void main(String[] args) {
		launch(args);
	}

	@Override
	public void start(Stage stage) throws Exception {
		AnchorPane anchorPane = new AnchorPane();
		GridPane gridPane = new GridPane();
		gridPane.setVgap(5);
		gridPane.setHgap(6);

		for(int i=0;i<6;i++){
			for(int k=0;k<5;k++){
				Rectangle rectangle = new Rectangle(70, 70);
				gridPane.add(rectangle, k, i);
				rectangle.setFill(Color.GRAY);
			}
		}

		ObservableList<Paint> colorsList=FXCollections.observableArrayList();

		Stop[] stops1 = new Stop[]{
				new Stop(0, Color.valueOf("#00EE00")),new Stop(0.5, Color.valueOf("#FFA500")),new Stop(1, Color.valueOf("#5D478B"))
		};
		LinearGradient  lg1 = new LinearGradient(0, 0, 70, 70, false, CycleMethod.NO_CYCLE, stops1);
		colorsList.add(lg1);


		Stop[] stops2 = new Stop[]{
				new Stop(0, Color.valueOf("#00EE00")),new Stop(0.5, Color.valueOf("#FFA500")),new Stop(1, Color.valueOf("#5D478B"))
		};
		LinearGradient  lg2 = new LinearGradient(0, 0, 1, 1, true, CycleMethod.NO_CYCLE, stops2);
		colorsList.add(lg2);


		Stop[] stops3 = new Stop[]{
				new Stop(0, Color.valueOf("#00EE00")),new Stop(0.5, Color.valueOf("#FFA500")),new Stop(1, Color.valueOf("#5D478B"))
		};
		LinearGradient  lg3 = new LinearGradient(0, 0, 0.5, 0.5, true, CycleMethod.REFLECT, stops3);
		colorsList.add(lg3);

		Stop[] stops4 = new Stop[]{
				new Stop(0, Color.valueOf("#00EE00")),new Stop(0.5, Color.valueOf("#FFA500")),new Stop(1, Color.valueOf("#5D478B"))
		};
		LinearGradient  lg4 = new LinearGradient(0, 0, 0.5, 0.5, true, CycleMethod.REPEAT, stops4);
		colorsList.add(lg4);

		Stop[] stops5 = new Stop[]{
				new Stop(0, Color.valueOf("#00EE00")),new Stop(0.5, Color.valueOf("#FFA50000")),new Stop(1, Color.valueOf("#5D478B"))
		};
		LinearGradient  lg5 = new LinearGradient(0, 0, 0.5, 0.5, true, CycleMethod.NO_CYCLE, stops5);
		colorsList.add(lg5);

		if(colorsList.size() > 0){
			for(int i=0;i<colorsList.size();i++){
				System.out.println("-----------------"+i);
				Rectangle rectangle = (Rectangle)gridPane.getChildren().get(i);
				rectangle.setFill(colorsList.get(i));
			}
		}



		anchorPane.getChildren().add(gridPane);
		stage.setScene(new Scene(anchorPane, 500, 500));
		stage.show();
	}

}

